package com.distribute.core.notify.redis;

import com.distribute.core.core.BaseCacheManageCell;
import com.distribute.core.core.BaseNotifyMessage;
import com.distribute.core.core.CacheManageContext;
import com.distribute.core.enums.NotifyFlushType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO
 *
 * @author chennengcheng
 * @date 2022-09-16 16:30
 * @remark
 */
public class RedisMessageListenerUtils {

    private static final Logger log = LoggerFactory.getLogger(RedisMessageListenerUtils.class);

    public static void process(BaseNotifyMessage redisBaseNotifyMessage) {
        String modelName = redisBaseNotifyMessage.getModel();
        String modelPrefix = redisBaseNotifyMessage.getModelPrefix();
        BaseCacheManageCell<BaseNotifyMessage> beanParser = CacheManageContext.getBeanParser(modelPrefix, modelName);
        int size;
        NotifyFlushType notifyFlushType = redisBaseNotifyMessage.getNotifyFlushType();
        if (notifyFlushType.equals(NotifyFlushType.ALL)) {
            size = beanParser.flushAllData();
        }else {
            size = beanParser.flushData(redisBaseNotifyMessage);
        }

        log.info(modelPrefix + ":" + modelName + " 本地缓存数据刷新完成， 共" + size + "条");
    }
}
